<!--
 * @Date: 2019-12-25 22:12:46
 * @LastEditors: 黄栋
 * @LastEditTime: 2020-03-25 13:15:21
 * @FilePath: /cloudAdmin/src/views/sale/SaleBussness.vue
 -->

<template>
  <div>
    <el-card>
      <el-form inline size="small">
        <el-form-item>
          <el-input v-model="searchForm.keyword" placeholder="请输入姓名/联系电话"></el-input>
        </el-form-item>
        <!-- <el-form-item label="投放时间">
          <el-date-picker
            v-model="searchForm.start_time"
            value-format="yyyy-MM-dd"
            type="date"
            style="width:140px"
            placeholder="选择日期"
          ></el-date-picker>
          <span style="margin:0 5px">-</span>
          <el-date-picker
            v-model="searchForm.end_time"
            value-format="yyyy-MM-dd"
            type="date"
            style="width:140px"
            placeholder="选择日期"
          ></el-date-picker>
        </el-form-item>-->
        <el-form-item>
          <el-button type="primary" @click="getDataList">查询</el-button>
        </el-form-item>
        <el-form-item style="float:right">
          <el-button type="primary" plain @click="$router.push('/publicPool')">添加商机</el-button>
        </el-form-item>
      </el-form>
      <div style="padding-bottom:10px">
        <el-button
          type="danger"
          size="mini"
          @click="deleteHandle()"
          :disabled="multipleSelection.length <= 0"
        >批量删除</el-button>
      </div>
      <el-table
        ref="multipleTable"
        :data="tableData"
        :header-cell-style="{background:'#F7F7F7',color:'#1E1E1E'}"
        @selection-change="handleSelectionChange"
        size="mini"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="link_co_name" label="公司名称" show-overflow-tooltip></el-table-column>
        <el-table-column prop="name" label="联系人" show-overflow-tooltip></el-table-column>
        <el-table-column prop="phone" label="联系电话" show-overflow-tooltip></el-table-column>
        <el-table-column prop="position" label="职位" show-overflow-tooltip></el-table-column>
        <el-table-column prop="end_time" label="商机保护" show-overflow-tooltip></el-table-column>
        <el-table-column prop="end_time" label="过期时间" sortable show-overflow-tooltip></el-table-column>
        <el-table-column label="操作" width="300px">
          <template slot-scope="{row}">
            <el-button type="text" size="mini" @click="detailList(row)">详情</el-button>
            <el-button type="text" size="mini" @click="editList(row)">编辑</el-button>
            <!-- <el-button type="text" size="mini">发起合同</el-button>
            <el-button type="text" size="mini">模版管理</el-button>-->
            <el-button type="text" size="mini" @click="deleteHandle(row.id)">移除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div style="margin-top:10px"></div>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="searchForm.page"
        :page-sizes="[10, 50, 100, 200]"
        :page-size="searchForm.page_num"
        layout=" sizes, prev, pager, next, jumper"
        :total="listTotal"
      ></el-pagination>
    </el-card>
    <saleBussnessEdit v-if="showEdit" ref="bussnessEdit" @refreshDataList="getDataList" />
    <SaleBussnessDetail v-if="showDetail" ref="bussnessDetail"></SaleBussnessDetail>
  </div>
</template>

<script>
import { get_sale_customer_List, del_customer_users } from "@/utils/api/sale";
import { mapState, mapActions } from "vuex";
import saleBussnessEdit from "./saleBussnessEdit";
import SaleBussnessDetail from "./SaleBussnessDetail";
export default {
  components: { saleBussnessEdit, SaleBussnessDetail },
  data() {
    return {
      searchForm: {}, //查询条件
      listTotal: 0, //总条数
      multipleSelection: [], //多选
      tableData: [], //表格数据
      showEdit: false,
      showDetail: false
    };
  },
  created() {
    this.initForm();
  },
  methods: {
    initForm() {
      this.searchForm = {
        page: 1, //当前页
        page_num: 10, //页数
        keywords: "", //关键字
        start_time: "", //考试时件
        end_time: "" //结束时间
      };
      this.getDataList();
    },
    /**获取表格数据 */
    getDataList() {
      get_sale_customer_List(this.searchForm).then(res => {
        if (res.code == 200) {
          this.tableData = res.data.list;
          this.listTotal = res.data.total;
        }
      });
    },
    /**详情 */
    detailList(data) {
      this.showDetail = true;
      this.$nextTick(() => {
        this.$refs.bussnessDetail.initData(data.customer_id);
      });
    },
    /**编辑 */
    editList(data) {
      this.showEdit = true;
      this.$nextTick(() => {
        this.$refs.bussnessEdit.initData(data.customer_id);
      });
    },

    // 删除
    deleteHandle(id) {
      var ids = id
        ? [id]
        : this.multipleSelection.map(item => {
            return item.id;
          });
      this.$confirm(
        `确定对[id=${ids.join(",")}]进行[${id ? "删除" : "批量删除"}]操作?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(() => {
          del_customer_users({
            id: ids,
            last_connect_time: "",
            last_connect: ""
          }).then(data => {
            if (data && data.code == 200) {
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
                onClose: () => {
                  this.getDataList();
                }
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        })
        .catch(() => {});
    },
    /**多选 */
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    /**每页数 */
    handleSizeChange(val) {
      this.searchForm.page_num = val;
      this.searchForm.page = 1;
      this.getDataList();
    },
    /**当前页 */
    handleCurrentChange(val) {
      this.searchForm.page = val;
      this.getDataList();
    }
  }
};
</script>
 